#define _CRT_SECURE_NO_WARNINGS  1
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<stdbool.h>

typedef int datatype;

typedef struct stack
{
	datatype* arr;
	int top;
	int capacity;
}ST;


void StackInit(ST* ps)
{
	assert(ps);

	ps->arr = (datatype*)malloc(sizeof(datatype) * 4);
	ps->capacity = 4;
	ps->top = 0;
}
void StackInsert(ST* ps, datatype x)
{
	assert(ps);
	if (ps->capacity == ps->top)
	{
		datatype* new = realloc(ps->arr, 2 * sizeof(datatype) * ps->capacity);
		if (new == NULL)
		{
			perror("realloc fail");
			return;
		}

		ps->arr = new;
		ps->capacity *= 2;
	}

	ps->arr[ps->top] = x;
	ps->top++;
}
bool StackEmpty(ST* ps)
{
	assert(ps);

	if (ps->top == 0)
	{
		return true;
	}
	else
		return false;
}
datatype StackTop(ST* ps)
{
	assert(ps);
	assert(StackEmpty);

	return ps->arr[ps->top - 1];

}
void StackPop(ST* ps)
{
	assert(ps);
	assert(StackEmpty);

	ps->top--;
}

void StackPrint(ST* ps)
{
	assert(ps);

	int i = 0;
	for (i = 0; i < ps->top; i++)
	{
		printf("%d ", ps->arr[i]);
	}
	printf("\n");

}


void StackDestroy(ST* ps)
{
	free(ps->arr);
	ps->arr = NULL;
	ps->capacity = 0;
	ps->top = 0;
}
int main()
{

}